package com.ehome.poct.core.controller;

import com.ehome.poct.core.api.dto.check.OnlineCheckDTO;
import com.ehome.poct.core.api.virtual.OnlineCheckService;
import com.ehome.poct.core.api.vo.online.TodoOrderVO;
import com.ehome.web.annotation.RequestLog;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 检测控制器类
 *
 * @author cq
 * @since 2022/02/03 18:10
 **/
@Api(tags = "联合检查处理")
@ApiSupport(author = "cq")
@RequestMapping("/onlinecheckprocess")
@RestController
@AllArgsConstructor
public class OnlineCheckController {
    @Autowired
    private OnlineCheckService onlineCheckService;

    /**
     * 开始处理检测
     *
     * @param checkDTO 推送到mqtt的患者消息
     * @return 带处理带列表
     */
    @ApiOperation("发起联机检测")
    @PostMapping("/doonlinecheck")
    @RequestLog
    public TodoOrderVO startOnline(@RequestBody OnlineCheckDTO checkDTO) {
        return onlineCheckService.startOnline(checkDTO);
    }

    /**
     * 获取待检测列表
     *
     * @param clinicId 诊所ID
     * @return 诊所待检测的列表
     */
    @ApiOperation("获取待检测列表")
    @GetMapping("/todo/{clinicId}")
    public List<TodoOrderVO> getTodoList(@PathVariable Long clinicId) {
        return onlineCheckService.getTodoList(clinicId);
    }

    /**
     * 删除联测待检测订单
     *
     * @param recordId 联合检测记录ID
     */
    @ApiOperation("删除联测待检测订单")
    @DeleteMapping("/del/record/{recordId}")
    @RequestLog
    public Boolean delTodoOrder(@PathVariable Long recordId) {
        return onlineCheckService.delTodoOrder(recordId);
    }

    /**
     * 校验单子是否还正常存在
     *
     * @param recordId 记录ID
     * @return true存在
     */
    @ApiOperation("校验单子是否还正常存在")
    @GetMapping("/todo/isExist/{recordId}")
    public Boolean todoIsExist(@PathVariable Long recordId) {
        return onlineCheckService.todoIsExist(recordId);
    }

    /**
     * 更新联测记录状态为完成
     *
     * @param recordId 记录ID
     */
    @ApiOperation("更新联测记录状态为完成")
    @PutMapping("/edit/record/{recordId}")
    public Boolean editUniRecord(@PathVariable Long recordId) {
        return onlineCheckService.editUniRecord(recordId);
    }

}
